const Service = require('egg').Service
class DraftService extends Service {
	constructor(ctx) {
		super(ctx)
	}
	async index(params) {
		let { pageSize = 10, pageNum = 1 } = params
		pageSize = Number(pageSize)
		const offset = (pageNum - 1) * pageSize
		const data = await this.ctx.model.Article.findAndCountAll({
			include: [
				{
					model: this.ctx.model.User,
					attributes: ['username'],
				},
				{
					model: this.ctx.model.Tag,
					attributes: ['tagName'],
				},
			],
			where: {
				status: 0,
			},
			limit: pageSize,
			offset,
			distinct: true,
		})
		return data
	}
}

module.exports = DraftService
